/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package model;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author ΖΑΧΑΡΙΑΣ ΤΣΟΥΡΑΛΑΚΗΣ
 */
@Entity
@Table(name = "MUSIC_GENRE")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "MusicGenre.findAll", query = "SELECT m FROM MusicGenre m"),
    @NamedQuery(name = "MusicGenre.findByMusicGenreId", query = "SELECT m FROM MusicGenre m WHERE m.musicGenreId = :musicGenreId"),
    @NamedQuery(name = "MusicGenre.findByName", query = "SELECT m FROM MusicGenre m WHERE m.name = :name")})
public class MusicGenre implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "MUSIC_GENRE_ID")
    private Integer musicGenreId;
    @Basic(optional = false)
    @Column(name = "NAME")
    private String name;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "musicGenre")
    private List<Artist> artistList;

    public MusicGenre() {
    }

    public MusicGenre(Integer musicGenreId) {
        this.musicGenreId = musicGenreId;
    }

    public MusicGenre(Integer musicGenreId, String name) {
        this.musicGenreId = musicGenreId;
        this.name = name;
    }

    public Integer getMusicGenreId() {
        return musicGenreId;
    }

    public void setMusicGenreId(Integer musicGenreId) {
        this.musicGenreId = musicGenreId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    @XmlTransient
    public List<Artist> getArtistList() {
        return artistList;
    }

    public void setArtistList(List<Artist> artistList) {
        this.artistList = artistList;
    }

   public ArrayList<ArrayList> read(Boolean Next)   {
       String Sql="Select * From Music_Genre Where Music_Genre_Id > " + musicGenreId.toString();
       if(Next==false){
           Sql = "Select * From Music_Genre Where Music_Genre_Id = " + musicGenreId.toString();
       } 
       dataLayer DataLayer = new dataLayer();
       ResultSet res = DataLayer.ExecuteQuery(Sql);
       ArrayList<ArrayList> list = new ArrayList<ArrayList>();
       name = "";
       try 
            {
                 while (res.next()) {
                     ArrayList<String> row = new ArrayList<>();
                     
                     this.musicGenreId=res.getInt("Music_Genre_Id");
                     this.name=res.getString("Name");                    
                     
                     row.add(this.musicGenreId.toString());
                     row.add(this.name);
                     
                     list.add(row);                     
                  }
            }
             catch ( SQLException err ) {
                System.out.println( err.getMessage( ) );
             }  
       return list;
    }
    
    @Override
    public int hashCode() {
        int hash = 0;
        hash += (musicGenreId != null ? musicGenreId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof MusicGenre)) {
            return false;
        }
        MusicGenre other = (MusicGenre) object;
        if ((this.musicGenreId == null && other.musicGenreId != null) || (this.musicGenreId != null && !this.musicGenreId.equals(other.musicGenreId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "model.MusicGenre[ musicGenreId=" + musicGenreId + " ]";
    }
    
}
